package org.hqs.queueno.service;

import org.hqs.feign.clients.ArrangementClient;
import org.hqs.feign.clients.PatientClient;
import org.hqs.feign.pojo.Arrangement;
import org.hqs.feign.pojo.Doctor;
import org.hqs.feign.pojo.Patient;
import org.hqs.queueno.mapper.QueueNoMapper;
import org.hqs.queueno.pojo.QueueNo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Queue;

@Service
public class QueueNoService {


    @Autowired
    private QueueNoMapper queueNoMapper;

    @Autowired
    private PatientClient patientClient;

    @Autowired
    private ArrangementClient arrangementClient;


    public QueueNoService(QueueNoMapper queueNoMapper) {
        this.queueNoMapper = queueNoMapper;
    }


    public List<QueueNo> getAllQueueNos() {
        List<QueueNo> queueNos = queueNoMapper.getAllQueueNos();
        for (int i = 0; i < queueNos.size(); i++) {
            QueueNo queueNo = queueNos.get(i);

            Arrangement arrangement = arrangementClient.getArrangementById(queueNo.getArrangementId()).getData();
            Patient patient = patientClient.queryById(Long.valueOf(queueNo.getPatientId())).getData();

            queueNo.setArrangement(arrangement);
            queueNo.setPatient(patient);
            queueNos.set(i, queueNo);
        }
        return queueNos;
    }


    public QueueNo getQueueNoById(int id) {
        QueueNo queueNo = queueNoMapper.getQueueNoById(id);
        Arrangement arrangement = arrangementClient.getArrangementById(queueNo.getArrangementId()).getData();
        Patient patient = patientClient.queryById(Long.valueOf(queueNo.getPatientId())).getData();

        queueNo.setArrangement(arrangement);
        queueNo.setPatient(patient);
        return queueNo;
    }


    public int insertQueueNo(QueueNo queueNo) {
        return queueNoMapper.insertQueueNo(queueNo);
    }


    public int updateQueueNo(QueueNo queueNo) {
        return queueNoMapper.updateQueueNo(queueNo);
    }


    public int deleteQueueNoById(int id) {
        return queueNoMapper.deleteQueueNoById(id);
    }
}
